package com.scientific.research.gobang.utils;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.util.Map;

public class RocketMqUtils {
    public static void runCodeSendMessage(Map map) {
        DefaultMQProducer producer = new DefaultMQProducer("codeandcode-group");
        producer.setNamesrvAddr("101.200.189.66:9876");

        try {
            producer.start();
        } catch (MQClientException e) {
            e.printStackTrace();
        }

        String sendMsg = JsonUtils.toString(map);
        Message msg = new Message("runCodeMessage", "oneCode", sendMsg.getBytes());
        SendResult sendResult = null;

        try {
            sendResult = producer.send(msg, 10000);
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println(sendResult);
        producer.shutdown();
    }
}
